package com.xpgk.mvc.bturnClass;

import java.util.List;
import java.util.Map;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.productSales.ProductSales;
import com.xpgk.mvc.productSales.ProductSalesOrder;

public class BturnClassController  extends	BaseController{
	
	
	private BturnClassService  bturnClassService;
	
	public  void  index()
	{
		render("BturnClass.html");
	}
	/**获取疗程下拉框
	 * 
	 */
	public  void  getLc()
	{	
		String  lcids=Code.lc_ids;
		String  sql=getSqlMy(Product.sqlId_getProductsByType);
		List<Product>  pList=Product.dao.find(sql,lcids);
		renderJson(pList);
	}
	/**根据id查出疗程产品信息
	 * 
	 */
	public  void getLcProByIds()
	{	
		//获取当前登录机构id
		String  orgIds=getCUserOrganIds();
		String lcproIds=getPara("lcproIds");
		String  sql=getSqlMy(Product.sqlId_selProByIds);
		Product  p=Product.dao.findFirst(sql,lcproIds,orgIds);
		setAttr("product", p);
		render("newLc.html");
	}
	/**获取顾客已有疗程
	 * 
	 */
	public void  getLcByCus()
	{
		String  cusIds=getPara("customerIds");
		//获取当前登录机构id
		String  orgIds=getCUserOrganIds();
		Map<String, Object>   m=bturnClassService.getLcByCus(cusIds,orgIds);
		setAttr("msg", m.get("msg"));
		setAttr("customerProduct", m.get("customerProduct"));
		setAttr("product", m.get("newlc"));
		setAttr("newTotal", m.get("newTotal"));
		setAttr("newNumber", m.get("newNumber"));
		
		render("lcInfo.html");
	}
	
	/**疗程转型结算
	 * 
	 */
	@Before(Tx.class)
	public  void jiesuan()
	{
		Product  p=getModel(Product.class);
		Customer c=getModel(Customer.class);
		ProductSales  ps=getModel(ProductSales.class);
		ProductSalesOrder pso=getModel(ProductSalesOrder.class);
		//获取当前登录机构id
		String  orgIds=getCUserOrganIds();
		//获取当前用户ids
		String userIds=getCUserIds();
		String oldProIds=getPara("oldProIds");
		
		String  msg=bturnClassService.jiesuan(p,c,ps,pso,orgIds,userIds,oldProIds);
		renderText(msg);
	}
}
